package com.sticktogether;


import android.app.Activity;
import android.content.Intent;
import android.os.Bundle;
import android.view.View;
import android.widget.EditText;
import android.widget.TextView;

import com.sticktogether.multiphotoselect.MultiPhotoSelectActivity;
import com.sticktogether.server.ServerCommunication;

public class SigninActivity extends Activity {

	public TextView Textfeld;
	public EditText Textbox_username;
	public EditText Textbox_password;
	
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_signin);
		
        Textfeld = (TextView) this.findViewById(R.id.textView1);
        Textbox_username = (EditText) this.findViewById(R.id.user);
        Textbox_password = (EditText) this.findViewById(R.id.password);
	}
	
	@Override
	protected void onResume() {
		if(getIntent().getBooleanExtra("logout", false)) {
        	ServerCommunication.deleteStoredPassword();
        }
		else {
			// check if we already have user_id and password stored on device and login if so
	        ServerCommunication.login(this);
		}
		super.onResume();
	}
	
	@Override
	public void onBackPressed() {
		Intent i = new Intent();
		i.setAction(Intent.ACTION_MAIN);
		i.addCategory(Intent.CATEGORY_HOME);
		this.startActivity(i); 
	}
	
    // Send button was pressed
    public void senden(View v) {
    	// ok check the username and the password in the textboxes and login if they are correct
    	ServerCommunication.login(this, Textbox_username.getText().toString(), Textbox_password.getText().toString());
    }
    
    public void upload(View v) {
		// Go to login page
		Intent intent = new Intent(this,MultiPhotoSelectActivity.class);
		startActivity(intent);
    }


}
